// pages/user_centre/settings/settings.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    WordsNum: [10, 15, 20, 25, 30, 35, 40, 45, 50],
    todayIndex: 3,
    reviewIndex: 3,
    batch: 25,
    reviewNumber: 25,
    isShield: false
  },


  /**
   * 屏蔽开关
   */
	isShield(e) {
    console.log(e)
    wx.setStorageSync("isShield", e.detail.value)
    this.setData({
      isShield: e.detail.value
    })
    if (this.data.isShield) {
      wx.cloud.callFunction({
        // 要调用的云函数名称
        name: 'block',
        // 传递给云函数的参数
        data: {},
        success: res => {
          // output: res.result === 3
          console.log("callFunction block", res)
        },
        fail: err => {
          // handle error
          console.log("callFunction block", err)
        },
        complete: () => {
          // ...
        }
      })
    } else {
      wx.cloud.callFunction({
        // 要调用的云函数名称
        name: 'unblock',
        // 传递给云函数的参数
        data: {},
        success: res => {
          // output: res.result === 3
          console.log("callFunction unBlock", res)
        },
        fail: err => {
          // handle error
          console.log("callFunction unBlock", err)
        },
        complete: () => {
          // ...
        }
      })
    }

  },

  /**
   * 点击更多关于
   */
  about() {
    wx.navigateTo({
      url: '/pages/user_centre/about/about',
    })
  },



  /**
   * 点击意见反馈
   */
  feedback() {
    wx.navigateTo({
      url: '/pages/user_centre/feedback/feedback',
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var batch = wx.getStorageSync('batch');
    if (batch == null) {
      this.setData({
        batch: 25
      })
    } else {
      this.setData({
        batch: batch
      })
    }
    var reviewNumber = wx.getStorageSync('reviewNumber');
    if (reviewNumber == null) {
      this.setData({
        reviewNumber: 25
      })
    } else {
      this.setData({
        reviewNumber: reviewNumber
      })
    }
    var todayIndex = wx.getStorageSync('todayIndex');
    if (!wx.getStorageSync("todayIndex")) {
      wx.setStorageSync("todayIndex", 3)
      this.setData({
        todayIndex: 3
      })
    } else {
      this.setData({
        todayIndex: todayIndex
      })
    }
    var reviewIndex = wx.getStorageSync('reviewIndex');
    if (!wx.getStorageSync("reviewIndex")) {
      wx.setStorageSync("reviewIndex", 3)
      this.setData({
        reviewIndex: 3
      })
    } else {
      this.setData({
        reviewIndex: reviewIndex
      })
    }


    //设置屏蔽
    if (wx.getStorageSync('isShield')) {
      this.setData({
        isShield: wx.getStorageSync('isShield')
      })
    }



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  //确定时触发该事件
  bindPickerChange1(e) {
    this.setData({
      todayIndex: e.detail.value,
      batch: this.data.WordsNum[e.detail.value]
    })
    wx.setStorageSync('batch', this.data.WordsNum[e.detail.value])
    wx.setStorageSync('todayIndex', e.detail.value)
  },

  bindPickerChange2(e) {
    this.setData({
      reviewIndex: e.detail.value,
      reviewNumber: this.data.WordsNum[e.detail.value]
    })
    wx.setStorageSync('reviewNumber', this.data.WordsNum[e.detail.value])
    wx.setStorageSync('reviewIndex', e.detail.value)
  },
})